﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace WP09S03_OfficeTracking
{
    public delegate void OnInvlidKey(char c);

    public partial class CodeFieldUControl : UserControl
    {
        private string specialChars;

        public OnInvlidKey invalidKey;

        public CodeFieldUControl()
        {
            specialChars = "_[]-";
            invalidKey = null;
            InitializeComponent();
        }


        public string LabelCaption
        {
            get { return this.label1.Text; }
            set { this.label1.Text = value; }
        }

        public TextBox TextBox{
           get { return textBox1;}
        }

        public Label Label
        {
            get { return label1; }
        }

        public string SpecialChars
        {
            get { return specialChars; }
            set { specialChars = value; }
        }

        public int MaxLength
        {
            get { return this.textBox1.MaxLength; }
            set { this.textBox1.MaxLength = value; }
        }

        public CharacterCasing UpperCase
        {
            get { return textBox1.CharacterCasing; }
            set { this.textBox1.CharacterCasing = value; }
        }

        public bool IsPasswordEntry
        {
            get { return this.textBox1.UseSystemPasswordChar; }
            set {
                if (value)
                    this.textBox1.PasswordChar = '*';
                //else
                 //   this.textBox1.PasswordChar = '';

                this.textBox1.UseSystemPasswordChar = value; }
        }

        public string UserText
        {
            get { return this.textBox1.Text; }
            set { this.textBox1.Text = value; }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
                char c = e.KeyChar;
                string stringChar = "";
                stringChar += c;
                if (System.Char.IsControl(c) == false &&
                    System.Char.IsLetterOrDigit(c) == false &&
                    specialChars.Contains(stringChar) == false)
                {
                    e.Handled = true;
                    //currentText = currentText.Remove(i, 1);
                    //MessageBox.Show("Invalid char" + stringChar);
                    if (invalidKey != null)
                        invalidKey(c);
                }



        }

    }

  
}
